home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 140 / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan).7z / Gekkan Dennou Club - 2000.1 Vol. 140 (Japan) (Track 1).bin / tools / dshell / dsh333bs.lzh / font.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-10  |  3.9 KB  |  178 lines

  1. /*
  2.     dshell    v3
  3.  
  4.     フォントファイル関連
  5. */
  6.  
  7. #include    "dsh.h"
  8.  
  9.  
  10. /*
  11.     フォントファイル名の解釈と対応するフォント番号の取得
  12. */
  13. int
  14. getFontNo(uchar *p, uchar *cutPath, struct NAMECKBUF *fname, uchar termChr)
  15. {
  16.     uchar pflag = FALSE;
  17.     uchar c, cbak, *q = p;
  18.     int n, firstSect = 0;
  19.  
  20.     while ((c = *q++) > ' ' && c != termChr)
  21.         ;
  22.     q--;
  23.     cbak = *q;
  24.     *q = '\0';
  25.     while (c = *p++) {
  26.         if (c == '+')        // ドキュメントファイルと同一パスから探す
  27.             pflag = TRUE;
  28.         else
  29.             break;
  30.     }
  31.     if (c == '\0' || NAMECK(--p, fname) != 0) {
  32.         *q = cbak;
  33.         return -1;
  34.     }
  35.     if (pflag) {
  36.         char temp[256];
  37.         strcpy(temp, cutPath);
  38.         strcat(temp, p);
  39.         NAMECK(temp, fname);
  40.     }
  41.     *q = cbak;
  42.     strcat((char *)fname, fname->name);
  43.     for (q = (uchar *)fname; *q++ != '\0';)
  44.         ;
  45.     q -= 3;
  46.     if (q >= (uchar *)fname && isdigit(*q) && isdigit(*(q + 1))) {
  47.         firstSect = atoi(q);
  48.         if (firstSect < 1 || firstSect > 94)
  49.             firstSect = 0;
  50.     }
  51.     strcat((char *)fname, fname->ext);
  52.     dstrupr((char *)fname);
  53.  
  54.     for (n = 0; n < FONTMAX; n++) {
  55.         if (font16[n].fname == NULL) {
  56.             FILE *fp;
  57.             int fsize;
  58.  
  59.             font16[n].size = 0;
  60.             font16[n].fname = (char *)fname;
  61.             if ((fp = fopen((char *)fname, "rb")) != NULL) {
  62.                 fsize = dfilelength(fileno(fp));
  63.                 if (fsize == 2048 || fsize == 4096) {
  64.                     font16[n].size++;
  65.                     font16[n].sect = 0;
  66.                 } else if (fsize <= 32*94*94 && (fsize % (32*94)) == 0) {
  67.                     int nSect = fsize / (32*94);
  68.                     font16[n].size = nSect;
  69.                     if (firstSect > 0 && firstSect + nSect <= 94)
  70.                         font16[n].sect = firstSect;
  71.                     else if (nSect <= 2)
  72.                         font16[n].sect = 4;    // かな
  73.                     else if (nSect == 32)
  74.                         font16[n].sect = 16;    // 第1水準漢字
  75.                     else if (nSect == 47)
  76.                         font16[n].sect = 48;    // 第2水準漢字
  77.                     else
  78.                         font16[n].sect = 1;
  79.                 }
  80.                 fclose(fp);
  81.             }
  82.             font16[n].fname = NULL;
  83.             return n;
  84.         } else if (strEqu(font16[n].fname, (char *)fname)) {
  85.             return n;
  86.         }
  87.     }
  88.  
  89.     dabort("フォントファイル数が最大値を越えます");
  90.     return -1;
  91. }
  92.  
  93.  
  94. /*
  95.     フォントファイルを読み込む
  96.  
  97.     fontNo: フォントファイル管理情報の格納開始番号
  98. */
  99. int 
  100. readFontFile(int fontNo)
  101. {
  102.     FILE *fp;
  103.     int fsize;
  104.     int first, last;
  105.     char temp[100];
  106.     void *p;
  107.  
  108.     first = fontNo;
  109.     for (last = fontNo; last < FONTMAX && font16[last].fname != NULL; last++)
  110.         ;
  111.     for (; fontNo < CUT_MAX && font16[fontNo].fname != NULL; fontNo++) {
  112.         w_mes(0, "フォントファイルをロード中です");
  113.         w_mes(1, font16[fontNo].fname);
  114.         w_mes(2, "しばらくお待ち下さい");
  115.         sprintf(temp, "%3d / %3d", fontNo - first + 1, last - first);
  116.         w_mes(3, temp);
  117.  
  118.         font16[fontNo].pat = NULL;
  119.         if (font16[fontNo].size == 0) {
  120. SIZE_ERROR:
  121.             w_open();
  122.             sprintf(temp, "%s: ファイルサイズが不当です", font16[fontNo].fname);
  123. ERROR:
  124.             w_mes(0, temp);
  125.             w_mes(2, "処理を続けます");
  126.             w_wait(100);
  127.             continue;
  128.         }
  129.         if ((fp = fopen(font16[fontNo].fname, "rb")) == NULL) {
  130.             w_open();
  131.             sprintf(temp, "%sがオープンできません", font16[fontNo].fname);
  132.             goto ERROR;
  133.         }
  134.  
  135.         fsize = dfilelength(fileno(fp));
  136.         if (font16[fontNo].sect == 0) {
  137.             if (fsize != 2048 && fsize != 4096) {
  138.                 fclose(fp);
  139.                 goto SIZE_ERROR;
  140.             }
  141.             p = (void *)MALLOC(4096);
  142.             if ((int)p < 0) {
  143. NOMEM:
  144.                 fclose(fp);
  145.                 w_open();
  146.                 strcpy(temp, "メモリ不足です");
  147.                 goto ERROR;
  148.             }
  149.             if (fread(p, sizeof(char), fsize, fp) != fsize) {
  150. READ_ERROR:
  151.                 fclose(fp);
  152.                 MFREE(p);
  153.                 w_open();
  154.                 sprintf(temp, "%sが読み込めません", font16[fontNo].fname);
  155.                 goto ERROR;
  156.             }
  157. #if 0
  158.             if (fsize == 2048)
  159.                 memcpy(p + 2048, defFont16.table[0] + 2048, 2048);    // 半角カナ
  160. #endif
  161.         } else {
  162.             if (fsize != font16[fontNo].size * 32 * 94) {
  163.                 fclose(fp);
  164.                 goto SIZE_ERROR;
  165.             }
  166.             p = (void *)MALLOC(fsize);
  167.             if ((int)p < 0)
  168.                 goto NOMEM;
  169.             if (fread(p, sizeof(char), fsize, fp) != fsize)
  170.                 goto READ_ERROR;
  171.         }
  172.         font16[fontNo].pat = p;
  173.         fclose(fp);
  174.     }
  175.  
  176.     return fontNo;
  177. }
  178.